
function init(){
	$("#grid").kendoGrid({
		dataSource: {
	         type: "json",
	         transport: {
	        	 read: {
	                 url: urlSearch,
	                 dataType: "json",
	                 type: "get",
	                 data : {}
	             },
	         },
	         //pageSize: 10,
	         schema:{
		        data: "list",
		        total: function(data) {
	                return data.total;
	            },
	    	 },
	    	 aggregate: [
                 { field: "registerNums", aggregate: "sum"},
                 { field: "invitedRegisterNums", aggregate: "sum"},
                 { field: "tutorialCompletedNums", aggregate: "sum"},
                 { field: "dau", aggregate: "sum"},
                 { field: "vipNums", aggregate: "sum"},
                 { field: "newVipNums", aggregate: "sum"},
                 { field: "repeaterVipNums", aggregate: "sum"}
             ],
	    	 requestStart: function(e) {   
               e.sender.transport.options.read.data = utils.getParamsForSearch("frmSearch");
            },
   	     pageSize: 20,
   	     serverPaging: true,
	     },	    
	     sortable: false,         
        pageable: {
            refresh: true,
        },
        columns: [{
	    	 title: "Date",
	         field: "dateValue",
	         width: 100,
	         footerTemplate: "<div class='number'>Total:</div>",
	     },{
	         field: "registerNums",
	         title: "Reg Nums",
	         width: 100,
	         attributes:{class:"number"},
	         format: "{0:n0}",
	         footerTemplate: "<div class='number'>#=kendo.toString(sum, 'n0')#</div>",
	     }, {
	    	 title: "Invite Reg Nums",
	         field: "invitedRegisterNums",
	         width: 140,
	         attributes:{class:"number"},
	         format: "{0:n0}",
	         footerTemplate: "<div class='number'>#=kendo.toString(sum, 'n0')#</div>",
	     }, {
	    	 title: "Invite Reg Rate",
	         field: "invitedRegisterRate",
	         width: 140,
	         attributes:{class:"number"},
	         format: "{0:n2}%",
	         template: function(record){
	        	 return "<div class='number'>" + kendo.toString(record.invitedRegisterNums / record.registerNums * 100, 'n2') + "%</div>";
	         },
	         footerTemplate: function(record){
	        	 return "<div class='number'>" + kendo.toString(record.invitedRegisterNums.sum / record.registerNums.sum * 100, 'n2') + "%</div>";
	         }
	         
	     },{
	         field: "tutorialCompletedNums",
	         title: "Tut Completed Nums",
	         width: 160,
	         attributes:{class:"number"},
	         format: "{0:n0}",
	         footerTemplate: "<div class='number'>#=kendo.toString(sum, 'n0')#</div>",
	     },{
	    	 title: "Tut Completed Rate",
	         field: "tutorialCompletedRate",
	         width: 150,
	         attributes:{class:"number"},
	         format: "{0:n2}%",
	         template: function(record){
	        	 return "<div class='number'>" + kendo.toString(record.tutorialCompletedNums / record.registerNums * 100, 'n2') + "%</div>";
	         },
	         footerTemplate: function(record){
	        	 return "<div class='number'>" + kendo.toString(record.tutorialCompletedNums.sum / record.registerNums.sum * 100, 'n2') + "%</div>";
	         }
	     },{
	         field: "dau",
	         title: "Dau",
	         width: 100,
	         attributes:{class:"number"},
	         format: "{0:n0}",
	         footerTemplate: "<div class='number'>#=kendo.toString(sum, 'n0')#</div>",
	     },{
	         field: "vipNums",
	         title: "Vip Nums",
	         width: 100,
	         attributes:{class:"number"},
	         format: "{0:n0}",
	         footerTemplate: "<div class='number'>#=kendo.toString(sum, 'n0')#</div>",
	     },{
	         field: "newVipNums",
	         title: "New Vip Nums",
	         width: 120,
	         attributes:{class:"number"},
	         format: "{0:n0}",
	         footerTemplate: "<div class='number'>#=kendo.toString(sum, 'n0')#</div>",
	     },{
	         field: "repeaterVipNums",
	         title: "Repeater Vip Nums",
	         width: 150,
	         attributes:{class:"number"},
	         format: "{0:n0}",
	         footerTemplate: "<div class='number'>#=kendo.toString(sum, 'n0')#</div>",
	     },{
	         field: "",
	         title: "",
	     }], 
	     dataBound : function(e){
	    	
	     }
	});
}

function setAutoRefreshGrid(second)
{
	if(typeof(second) == "undefined")
		second = 10;
		
	setInterval(function(){
		$("#grid").data("kendoGrid").dataSource.read();
	}, second * 1000);
}

function search(){
	$("#grid").data("kendoGrid").dataSource.read();	// Reset grid
}
